package com.zh.note.huawei.onehundred.交换字符;

/**
 * @Author: zhanghuan
 * @date: 2023/9/1 14:09
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // String input = sc.nextLine();
        String input = "abacd";
        char[] chars = input.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            int minIndex = i;
            for (int j = i + 1; j < chars.length - 1; j++) {
                if (chars[minIndex] > chars[j]) {
                    minIndex = j;
                }
            }
            swap(i, minIndex, chars);
        }
        StringBuilder sb = new StringBuilder();
        for (char ch : chars) {
            sb.append(ch);
        }
        System.out.println(sb.toString());
    }

    private static void swap(int i, int j, char[] chars) {
        char temp = chars[i];
        chars[i] = chars[j];
        chars[j] = temp;
    }
}
